/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dio.com.gui;

import dio.com.model.bean.Empresa;
import dio.com.model.bean.Usuario;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

/**
 *
 * @author Diógenes
 */
public class RegistroAtividades extends javax.swing.JDialog {

    private DefaultTableModel tmPendencias = new DefaultTableModel(new Object [][] {
        {null, null, null}
    },
    new String [] {
        "Data", "Evento", "Visto"
    });

    /**
     * Creates new form RegistroAtividades
     */
    public RegistroAtividades(java.awt.Frame parent, boolean modal, Empresa empresa, Usuario usuario) {
        super(parent, modal);
        initComponents();
        setLocationRelativeTo(null);
        lblEmpresa.setText(empresa.getNome());
        montarTabela();
        tbEventos.getModel().setValueAt(usuario.getNome(), 0, 2);
        }

    private void carregarData() {
        GregorianCalendar agora = new GregorianCalendar();
        int dia = agora.get(Calendar.DAY_OF_MONTH);
        int mes = agora.get(Calendar.MONTH);
        int ano = agora.get(Calendar.YEAR);
        tbEventos.getModel().setValueAt(dia+"/"+mes+"/"+ano, 0, 0);        
        
        
    }
    
    private void montarTabela() {
        //CASO DE UMA NOVA LINHA OU SEJA UM INSERT
        //for (int i = 0; i < tbEventos.getRowCount(); i++) {
         //   tbEventos.getModel().setValueAt(usuario.getNome(), i, 2);
        //}
        tbEventos.setModel(tmPendencias);
        String[] campos = new String[]{null, null, null};
        tmPendencias.addRow(campos);
        
        //-----------------------------------------------------------------------------------
        tbEventos.setModel(new javax.swing.table.DefaultTableModel(
    new Object [][] {
        {null, null, null}
    },
    new String [] {
        "Data", "Evento", "Visto"
    }
) {
    Class[] types = new Class [] {
        java.lang.String.class, java.lang.String.class, java.lang.String.class
    };
    boolean[] canEdit = new boolean [] {
        false, true, false
    };

    public Class getColumnClass(int columnIndex) {
        return types [columnIndex];
    }

    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return canEdit [columnIndex];
    }
});
        
        ///------------------------------------------------
        jScrollPane2.setViewportView(tbEventos);

        tbEventos.getColumnModel().getColumn(0).setMinWidth(45);
        tbEventos.getColumnModel().getColumn(0).setPreferredWidth(50);
        tbEventos.getColumnModel().getColumn(0).setMaxWidth(60);
        tbEventos.getColumnModel().getColumn(2).setMinWidth(45);
        tbEventos.getColumnModel().getColumn(2).setPreferredWidth(50);
        tbEventos.getColumnModel().getColumn(2).setMaxWidth(60);
        
        carregarData();
    }
//    public static void main (String args []){
//        RegistroAtividades e = new RegistroAtividades(null, true);
//        e.setVisible(true);
//    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        lblEmpresa = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tbEventos = new javax.swing.JTable();
        btLinha = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Registro de Atividades");

        jLabel1.setText("Acompanhamento – Departamento Fiscal");

        jLabel2.setText("Empresa:");

        lblEmpresa.setText("...");

        tbEventos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null}
            },
            new String [] {
                "Data", "Evento", "Visto"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, true, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane2.setViewportView(tbEventos);
        tbEventos.getColumnModel().getColumn(0).setMinWidth(45);
        tbEventos.getColumnModel().getColumn(0).setPreferredWidth(50);
        tbEventos.getColumnModel().getColumn(0).setMaxWidth(60);
        tbEventos.getColumnModel().getColumn(2).setMinWidth(45);
        tbEventos.getColumnModel().getColumn(2).setPreferredWidth(50);
        tbEventos.getColumnModel().getColumn(2).setMaxWidth(60);

        btLinha.setText("+");
        btLinha.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btLinhaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblEmpresa))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btLinha)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(lblEmpresa))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btLinha)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(30, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btLinhaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btLinhaActionPerformed
        String[] campos = new String[]{null, null, null};
        tmPendencias.addRow(campos);
    }//GEN-LAST:event_btLinhaActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btLinha;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lblEmpresa;
    private javax.swing.JTable tbEventos;
    // End of variables declaration//GEN-END:variables
}
